home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Demos / Component Software / FileFlex 2.0.3.sit / FileFlex 2.0.3 / FileFlex-Director / FileFlex Xtras / -Database Designer / 00006_KeyInput Script.ls < prev    next >
Encoding:
Text File  |  1997-08-18  |  2.1 KB  |  68 lines

  1. -- Hang onto your hats.  Welcome to the monstrous keyDown hack.
  2. -- This ugly piece of coding wouldn't be necessary if text entry
  3. -- fields didn't use TextEdit and didn't require white backgrounds.
  4. -- Let's just hope you're smart enough to be using a fast machine.
  5.  
  6. on keyDown
  7.   global keyEditOK, fieldSpec
  8.   -- if you're not supposed to be editing, then get the
  9.   -- heck out of dodge
  10.   if keyEditOK = FALSE then exit
  11.   
  12.   -- now set up the edit field so we know where to put the
  13.   -- characters.
  14.   case (the frameLabel) of
  15.     "Create":
  16.       put "FieldEntry" into theField
  17.       put 10 into maxChars
  18.       set validChars to "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_" 
  19.       set valid1stChars to "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" 
  20.   end case
  21.   
  22.   -- process the keys themselves  
  23.   if the key = ENTER or the key = RETURN then
  24.     if field theField <> "_" then
  25.       -- Since the data field isn't empty, do something
  26.       case (the frameLabel) of
  27.         "Create":
  28.           -- process the "OK" button
  29.           doCreateOK
  30.       end case
  31.     end if
  32.   else
  33.     if the key = BACKSPACE then
  34.       put the number of chars of field theField into numChars
  35.       if numChars > 1 then
  36.         if numChars > 2 then
  37.           put char 1 to (numChars -2) of field theField & "_" into field theField
  38.         else
  39.           put "_" into field theField
  40.         end if
  41.       end if
  42.     else
  43.       put the number of chars of field theFIeld into numChars
  44.       if numChars <= maxChars then
  45.         if numChars = 1 then
  46.           -- process first character
  47.           if valid1stChars contains the key then
  48.             put toupperC(the key) & "_" into field theField
  49.           end if
  50.         else
  51.           -- process 2 through max chars
  52.           if validChars contains the key then
  53.             put char 1 to (numChars -1) of field theField¬¨
  54.               & toupperC(the key) & "_" into field theField
  55.           end if
  56.         end if
  57.       end if
  58.     end if
  59.   end if
  60. end keyDown
  61.  
  62. on toupperC theChar
  63.   if charToNum(theChar) >= 97 and charToNum(theChar) <= 122 then
  64.     return numToChar(charToNum(theChar)-32)
  65.   else
  66.     return theChar
  67.   end if
  68. end